<?php 
//标签云插件
class cy_tags extends WP_Widget {

	function cy_tags() {
		$widget_ops=array('description'=>'随机显示标签，可自定义数量，大小');
		$this->WP_Widget('cy_tags','&#xE000; 标签云',$widget_ops);
	}

	function form($instance) {
		$title=isset($instance['title'])? $instance['title']: '标签云集';
		$counts=isset($instance['counts'])? $instance['counts']: 32;
		$min_size=isset($instance['min_size'])? $instance['min_size']: 12;
		$max_size=isset($instance['max_size'])? $instance['max_size']: 20;
		$page_link=isset($instance['page_link'])? $instance['page_link']: '';
?>
	<p>
		<label>标题：
			<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
		</label>
	</p>

	<p>
		<label>标签数量：
			<input id="<?php echo $this->get_field_id('counts'); ?>" name="<?php echo $this->get_field_name('counts'); ?>" type="text" value="<?php echo $counts; ?>" size="6" />
		</label>
	</p>

	<p>
		<label>最小字号：
			<input id="<?php echo $this->get_field_id('min_size'); ?>" name="<?php echo $this->get_field_name('min_size'); ?>" type="text" value="<?php echo $min_size; ?>" size="6" />
		</label>
	</p>

	<p>
		<label>最大字号：
			<input id="<?php echo $this->get_field_id('max_size'); ?>" name="<?php echo $this->get_field_name('max_size'); ?>" type="text" value="<?php echo $max_size; ?>" size="6" />
		</label>
	</p>

	<p>
		<label>标签页面链接：
			<input class="widefat" id="<?php echo $this->get_field_id('page_link'); ?>" name="<?php echo $this->get_field_name('page_link'); ?>" type="text" value="<?php echo $page_link; ?>" />
		</label>
	</p>
<?php
	}

	function update($new_instance, $old_instance){return $new_instance;}

	function widget($args, $instance) {
		extract($args);
		$title=$instance['title'];
		$counts=$instance['counts'];
		$min_size=$instance['min_size'];
		$max_size=$instance['max_size'];
		$page_link=$instance['page_link'];
		echo $before_widget.$before_title.$title.$after_title;
		echo '<div class="cy_tags">';
		wp_tag_cloud('smallest='.$min_size.'&largest='.$max_size.'&unit=px&number='.$counts.'&orderby=count&order=RAND');
		echo '</div>';
		if($page_link) echo '<a class="more-tag" href="' . $page_link . '" rel=external >查看更多 →</a>';
		echo $after_widget;
	}
}
register_widget('cy_tags');
?>